	.module ds18b20.c
	.area text(rom, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\ds18b20.c
	.dbfunc e ds18b20_init _ds18b20_init fV
	.even
_ds18b20_init::
	.dbline -1
	.dbline 14
; 
; #include "hw_config.h"
; #include "ds18b20.h"
; 
; 
; 
; /*******************************************
; Function name: ds18b20_init
; Function: Reset DS18B20
; Parameters: None
; Return Value: None
; ********************************************/
; void ds18b20_init(void)
; {
	.dbline 15
; 	DS18B20_DDR|=(1<<DS18B20_PIN_NO);			// configure output
	lds R24,100
	ori R24,16
	sts 100,R24
	.dbline 16
; 	DS18B20_PORT&=~(1<<DS18B20_PIN_NO);			// delay_us
	lds R24,101
	andi R24,239
	sts 101,R24
	.dbline 17
; 	delay_us(600*2);
	ldi R16,1200
	ldi R17,4
	xcall _delay_us
	.dbline 18
; 	DS18B20_PORT|=(1<<DS18B20_PIN_NO);			// release bus
	lds R24,101
	ori R24,16
	sts 101,R24
	.dbline 19
; 	delay_us(60*2);
	ldi R16,120
	ldi R17,0
	xcall _delay_us
	.dbline 20
; 	DS18B20_DDR&=~(1<<DS18B20_PIN_NO);			// configured for input
	lds R24,100
	andi R24,239
	sts 100,R24
L4:
	.dbline 21
; 	while((DS18B20_PIN&(1<<DS18B20_PIN_NO)));	// wait down DS18B20
L5:
	.dbline 21
	lds R2,99
	sbrc R2,4
	rjmp L4
X0:
L7:
	.dbline 22
; 	while(!(DS18B20_PIN&(1<<DS18B20_PIN_NO))); // wait for the release of the bus DS18B20
L8:
	.dbline 22
	lds R2,99
	sbrs R2,4
	rjmp L7
X1:
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ds18b20_readB _ds18b20_readB fc
;           retd -> R20
;              i -> R22
	.even
_ds18b20_readB::
	xcall push_xgsetF000
	.dbline -1
	.dbline 32
; }
; 
; /*******************************************
; Function name: ds18b20_readB
; Function: read a byte of data
; Parameters: None
; Return Value: retd - a byte of data returned
; ********************************************/
; byte ds18b20_readB(void)
; {
	.dbline 33
; 	byte i,retd=0;
	clr R20
	.dbline 35
; 	
; 	for(i=0;i<8;i++)	 			// bit count
	clr R22
	xjmp L14
L11:
	.dbline 36
; 	{
	.dbline 37
; 		retd>>=1;						// right, ready to accept new data bits
	lsr R20
	.dbline 38
; 		DS18B20_DDR|=(1<<DS18B20_PIN_NO);			// configure output
	lds R24,100
	ori R24,16
	sts 100,R24
	.dbline 39
; 		DS18B20_PORT&=~(1<<DS18B20_PIN_NO);			// down, start reading data bits
	lds R24,101
	andi R24,239
	sts 101,R24
	.dbline 40
; 		DS18B20_PORT|=(1<<DS18B20_PIN_NO);			// release bus
	lds R24,101
	ori R24,16
	sts 101,R24
	.dbline 41
; 		delay_us(5*2);
	ldi R16,10
	ldi R17,0
	xcall _delay_us
	.dbline 42
; 		DS18B20_DDR&=~(1<<DS18B20_PIN_NO);			// configured as inputs, starts reading the data bits
	lds R24,100
	andi R24,239
	sts 100,R24
	.dbline 44
; 		
; 		if(DS18B20_PIN&(1<<DS18B20_PIN_NO))			// This bit is high
	lds R2,99
	sbrs R2,4
	rjmp L15
X2:
	.dbline 45
; 		{
	.dbline 46
; 			retd|=0x80;					// this location is high on
	ori R20,128
	.dbline 47
; 		}
L15:
	.dbline 48
; 			delay_us(50*2);					// Wait 50 microseconds
	ldi R16,100
	ldi R17,0
	xcall _delay_us
	.dbline 49
; 	}
L12:
	.dbline 35
	inc R22
L14:
	.dbline 35
	cpi R22,8
	brlo L11
X3:
	.dbline 50
; 	return retd;					// will return one byte read
	mov R16,R20
	.dbline -2
L10:
	.dbline 0 ; func end
	xjmp pop_xgsetF000
	.dbsym r retd 20 c
	.dbsym r i 22 c
	.dbend
	.dbfunc e ds18b20_writeB _ds18b20_writeB fV
;              i -> R20
;            wrd -> R10
	.even
_ds18b20_writeB::
	xcall push_xgset300C
	mov R10,R16
	.dbline -1
	.dbline 61
; 	
; }
; 
; /*******************************************
; Function name: B20_writeB
; Function: write a byte of data
; Parameters: wrd - data to be written
; Return Value: None
; ********************************************/
; void ds18b20_writeB(byte wrd)
; {
	.dbline 63
; 	byte i;
; 	for(i=0;i<8;i++)	  	        // bit count
	clr R20
	xjmp L21
L18:
	.dbline 64
; 	{
	.dbline 65
; 		DS18B20_DDR|=(1<<DS18B20_PIN_NO);			// configure output
	lds R24,100
	ori R24,16
	sts 100,R24
	.dbline 66
; 		DS18B20_PORT&=~(1<<DS18B20_PIN_NO);			// down, start writing data bits
	lds R24,101
	andi R24,239
	sts 101,R24
	.dbline 67
; 		delay_us(1*2);
	ldi R16,2
	ldi R17,0
	xcall _delay_us
	.dbline 69
; 		
; 		if(wrd&0x01)					// this bit is high
	sbrs R10,0
	rjmp L22
X4:
	.dbline 70
; 		{
	.dbline 71
; 			DS18B20_PORT|=(1<<DS18B20_PIN_NO);			// is a single bus will be pulled high
	lds R24,101
	ori R24,16
	sts 101,R24
	.dbline 72
; 		}
	xjmp L23
L22:
	.dbline 74
; 		else
; 		{
	.dbline 75
; 			DS18B20_PORT&=~(1<<DS18B20_PIN_NO);		// is a low-down will be a single bus
	lds R24,101
	andi R24,239
	sts 101,R24
	.dbline 76
; 		}
L23:
	.dbline 78
; 		
; 		delay_us(50*2);
	ldi R16,100
	ldi R17,0
	xcall _delay_us
	.dbline 79
; 		DS18B20_PORT|=(1<<DS18B20_PIN_NO); // release bus
	lds R24,101
	ori R24,16
	sts 101,R24
	.dbline 80
; 		wrd>>=1;						// right, to write the new data bit in preparation
	lsr R10
	.dbline 81
; 	}
L19:
	.dbline 63
	inc R20
L21:
	.dbline 63
	cpi R20,8
	brlo L18
X5:
	.dbline 82
; 	delay_us(50);
	ldi R16,50
	ldi R17,0
	xcall _delay_us
	.dbline -2
L17:
	.dbline 0 ; func end
	xjmp pop_xgset300C
	.dbsym r i 20 c
	.dbsym r wrd 10 c
	.dbend
	.dbfunc e read_ds18b20_temperature _read_ds18b20_temperature fi
;      tempcount -> R10,R11
;          temph -> R12
;          templ -> R10
	.even
_read_ds18b20_temperature::
	xcall push_xgset003C
	.dbline -1
	.dbline 86
; }
; 
; u16 read_ds18b20_temperature(void)
; {
	.dbline 90
; 	byte templ,temph;
; 	u16 tempcount;
; 	
; 	ds18b20_init();	      // initialize, initialize each write command from the beginning
	xcall _ds18b20_init
	.dbline 91
; 	ds18b20_writeB(0xcc); 	  // skip ROM
	ldi R16,204
	xcall _ds18b20_writeB
	.dbline 92
; 	ds18b20_writeB(0x44); 	  // start temperature conversion
	ldi R16,68
	xcall _ds18b20_writeB
	.dbline 93
; 	ds18b20_init();	   	  // initialize each write command from the beginning
	xcall _ds18b20_init
	.dbline 94
; 	ds18b20_writeB(0xcc); 	  // skip ROM
	ldi R16,204
	xcall _ds18b20_writeB
	.dbline 95
; 	ds18b20_writeB(0xbe); 	  // read register
	ldi R16,190
	xcall _ds18b20_writeB
	.dbline 96
; 	templ=ds18b20_readB();	  // read temperature low byte
	xcall _ds18b20_readB
	mov R10,R16
	.dbline 97
; 	temph=ds18b20_readB();	  // read temperature high byte
	xcall _ds18b20_readB
	mov R12,R16
	.dbline 98
; 	tempcount=(temph<<8)|templ; // calculate the specific temperature
	mov R11,R12
	.dbline 100
; 	
; 	return(tempcount);
	movw R16,R10
	.dbline -2
L24:
	.dbline 0 ; func end
	xjmp pop_xgset003C
	.dbsym r tempcount 10 i
	.dbsym r temph 12 c
	.dbsym r templ 10 c
	.dbend
	.dbfunc e bsp_ds18b20_gpio_init _bsp_ds18b20_gpio_init fV
	.even
_bsp_ds18b20_gpio_init::
	.dbline -1
	.dbline 105
; } 
; 
; 
; void bsp_ds18b20_gpio_init(void)
; { 
	.dbline 106
; 	sbi(DS18B20_DDR, DS18B20_PIN_NO);
	lds R24,100
	ori R24,16
	sts 100,R24
	.dbline 107
; 	sbi(DS18B20_PORT, DS18B20_PIN_NO);
	lds R24,101
	ori R24,16
	sts 101,R24
	.dbline -2
L25:
	.dbline 0 ; func end
	ret
	.dbend
; }
; 
; 
